from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE `admin_role_dept` (
    `dept_id` INT NOT NULL REFERENCES `admin_dept` (`id`) ON DELETE CASCADE,
    `admin_role_id` INT NOT NULL REFERENCES `admin_role` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
        ALTER TABLE `admin_dept` ADD INDEX `idx_admin_dept_ancesto_850b7b` (`ancestors`);
        ALTER TABLE `admin_dept` ADD INDEX `idx_admin_dept_parent__21066f` (`parent_id`, `sort`);"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `admin_dept` DROP INDEX `idx_admin_dept_parent__21066f`;
        ALTER TABLE `admin_dept` DROP INDEX `idx_admin_dept_ancesto_850b7b`;
        DROP TABLE IF EXISTS `admin_role_dept`;"""
